package com.menggudf.service.impl;

import com.menggudf.entity.PersonalHistory;
import com.menggudf.mapper.PersonalHistoryDao;
import com.menggudf.service.PersonalHistoryService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * (PersonalHistory)表服务实现类
 *
 * @author makejava
 * @since 2025-02-20 16:58:32
 */
@Service("personalHistoryService")
public class PersonalHistoryServiceImpl implements PersonalHistoryService {
    @Resource
    private PersonalHistoryDao personalHistoryDao;

    /**
     * 通过ID查询单条数据
     *
     * @param pid 主键
     * @return 实例对象
     */
    @Override
    public PersonalHistory queryById(Integer pid) {
        return this.personalHistoryDao.queryById(pid);
    }

    /**
     * 分页查询
     *
     * @param personalHistory 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<PersonalHistory> queryByPage(PersonalHistory personalHistory, PageRequest pageRequest) {
        long total = this.personalHistoryDao.count(personalHistory);
        return new PageImpl<>(this.personalHistoryDao.queryAllByLimit(personalHistory, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param personalHistory 实例对象
     * @return 实例对象
     */
    @Override
    public PersonalHistory insert(PersonalHistory personalHistory) {
        this.personalHistoryDao.insert(personalHistory);
        return personalHistory;
    }

    /**
     * 修改数据
     *
     * @param personalHistory 实例对象
     * @return 实例对象
     */
    @Override
    public PersonalHistory update(PersonalHistory personalHistory) {
        this.personalHistoryDao.update(personalHistory);
        return this.queryById(personalHistory.getPid());
    }

    /**
     * 通过主键删除数据
     *
     * @param pid 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer pid) {
        return this.personalHistoryDao.deleteById(pid) > 0;
    }
}
